import sqlite3, datetime
from django.shortcuts import render
from django.http import HttpResponse
from shared_resources import *
	
def classroom(request, nr):
	initialize(request)
	nr = str(nr)
	output = """
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/static/classroom/kurento.png" type="image/png">

    <link rel="stylesheet" href="/static/classroom/bootstrap.min.css">
    <link rel="stylesheet" href="/static/classroom/index.css">
    <link rel="stylesheet" href="/static/classroom/ekko-lightbox.min.css">
    <link rel="stylesheet" href="/static/classroom/kurento.css">

    <script src="/static/classroom/jquery.min.js"></script><style type="text/css"></style>
    <script src="/static/classroom/bootstrap.min.js"></script>
    <script src="/static/classroom/ekko-lightbox.min.js"></script>
    <script src="/static/classroom/ekko-lightbox.min.js"></script>
    <script src="/static/classroom/adapter.js"></script>

    <script src="/static/classroom/kurento-client.js"></script>
    <script src="/static/classroom/kurento-utils.js"></script>
	"""
	if nr == "0":
		output += """<script src="/static/classroom/index(1).js"></script>"""
	else:
		output += """<script src="/static/classroom/index(2).js"></script>"""
	output += """
    <title>Kurento Tutorial 1: Hello World</title>
  </head>
  <body>

    <header>
      <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"></button>
            <a class="navbar-brand" href="#">Kurento Tutorial</a>
          </div>
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
              <li>
                <a href="https://github.com/Kurento/kurento-tutorial-js/tree/master/kurento-hello-world"><span class="glyphicon glyphicon-file"></span> Source Code</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </header>

    <div class="container">
      <div class="page-header">
        <h1>Tutorial 1: Hello World (WebRTC in loopback)</h1>
        <p>
          This application shows a <i>WebRtcEndpoint</i> connected to itself
          (loopback). Take a look to the . To run
          this demo follow these steps:
        </p>
        <ol>
          <li>Open this page with a browser compliant with WebRTC (Chrome, Firefox).</li>
          <li>Click on <i>Start</i> button.</li>
          <li>Grant the access to the camera and microphone. After the SDP negotiation the loopback should start.</li>
          <li>Click on <i>Stop</i> to finish the communication.</li>
        </ol>
      </div>
      <div class="row">
        <div class="col-md-5">
          <h3>Local stream</h3>
          <video id="videoInput" autoplay="" width="480px" height="360px" poster="img/webrtc.png"></video>
        </div>
        <div class="col-md-2">
          <a id="start" href="#" class="btn btn-success">
            <span class="glyphicon glyphicon-play"></span> Start</a>
          <br>
          <br>
          <a id="stop" href="#" class="btn btn-danger">
            <span class="glyphicon glyphicon-stop"></span> Stop</a>
        </div>
        <div class="col-md-5">
          <h3>Remote stream</h3>
          <video id="videoOutput" autoplay="" width="480px" height="360px" poster="img/webrtc.png"></video>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12">
          <label class="control-label" for="console">Console</label><br><br>
          <div id="console" class="democonsole">
            <ul></ul>
          </div>
        </div>
      </div>
    </div>

    <footer>
      <div class="foot-fixed-bottom">
        <div class="container text-center">
          <hr>
          <div class="row"> 2014-2015 Kurento</div>
          <div class="row">
            <div class="col-md-4">
              <a href="http://www.urjc.es/">
                <img src="/static/classroom/urjc.gif" alt="Universidad Rey Juan Carlos" height="50px">
              </a>
            </div>
            <div class="col-md-4">
              <a href="http://www.kurento.org/">
                <img src="/static/classroom/kurento.png" alt="Kurento" height="50px">
              </a>
            </div>
            <div class="col-md-4">
              <a href="http://www.naevatec.com/">
                <img src="/static/classroom/naevatec.png" alt="Naevatec" height="50px">
              </a>
            </div>
          </div>
        </div>
      </div>
    </footer>

  

</body></html>	
	"""
	
	return HttpResponse(output)
	
def test(request):
	import socket

	initialize(request)

	output = """
	<!DOCTYPE html>
	<!--
	 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
	 *
	 *  Use of this source code is governed by a BSD-style license
	 *  that can be found in the LICENSE file in the root of the source
	 *  tree.
	-->
	<html>
	<head>

	  <meta charset="utf-8">
	  <meta name="description" content="WebRTC code samples">
	  <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1">
	  <meta itemprop="description" content="Client-side WebRTC code samples">
	  <meta itemprop="image" content="../../../images/webrtc-icon-192x192.png">
	  <meta itemprop="name" content="WebRTC code samples">
	  <meta name="mobile-web-app-capable" content="yes">
	  <meta id="theme-color" name="theme-color" content="#ffffff">

	  <base target="_blank">

	  <title>getUserMedia</title>

	  <link rel="icon" sizes="192x192" href="../../../images/webrtc-icon-192x192.png">
	  <link href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" type="text/css">
	  <link rel="stylesheet" href="../../../css/main.css">

	</head>

	<body>

	  <div id="container">

		<div class="highlight">
		  <p>New codelab: <a href="https://codelabs.developers.google.com/codelabs/webrtc-web">Realtime communication with WebRTC</a></p>
		</div>

		<h1><a href="//webrtc.github.io/samples/" title="WebRTC samples homepage">WebRTC samples</a> <span>getUserMedia</span></h1>

		<video id="gum-local" autoplay></video>

		<div id="errorMsg"></div>

		<p class="warning"><strong>Warning:</strong> if you're not using headphones, pressing play will cause feedback.</p>

		<p>Display the video stream from <code>getUserMedia()</code> in a video element.</p>

		<p>The <code>MediaStream</code> object <code>stream</code> passed to the <code>getUserMedia()</code> callback is in global scope, so you can inspect it from the console.</p>

		<a href="https://github.com/webrtc/samples/tree/gh-pages/src/content/getusermedia/gum" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>
	  </div>

	  <script src="/static/adapter.js"></script>
	  <script>
'use strict';

var errorElement = document.querySelector('#errorMsg');
var video = document.querySelector('video');

// Put variables in global scope to make them available to the browser console.
var constraints = window.constraints = {
  audio: false,
  video: true
};

function handleSuccess(stream) {
  var videoTracks = stream.getVideoTracks();
  console.log('Got stream with constraints:', constraints);
  console.log('Using video device: ' + videoTracks[0].label);
  stream.oninactive = function() {
    console.log('Stream inactive');
  };
  window.stream = stream; // make variable available to browser console
  video.srcObject = stream;
}

function handleError(error) {
  if (error.name === 'ConstraintNotSatisfiedError') {
    errorMsg('The resolution ' + constraints.video.width.exact + 'x' +
        constraints.video.width.exact + ' px is not supported by your device.');
  } else if (error.name === 'PermissionDeniedError') {
    errorMsg('Permissions have not been granted to use your camera and ' +
      'microphone, you need to allow the page access to your devices in ' +
      'order for the demo to work.');
  }
  errorMsg('getUserMedia error: ' + error.name, error);
}

function errorMsg(msg, error) {
  errorElement.innerHTML += '<p>' + msg + '</p>';
  if (typeof error !== 'undefined') {
    console.error(error);
  }
}

navigator.mediaDevices.getUserMedia(constraints).
    then(handleSuccess).catch(handleError);	  
	  </script>
	</body>
	</html>
	"""
	
	return HttpResponse(output)	

